<?php
/**
 * Assert that checks if Post with $id from request belongs to current user
 *
 * @author Lukas Normantas
 */
class Blog_Assert_PostAuthor implements Zend_Acl_Assert_Interface
{
    /**
     * Returns true if Post blongs to current user
     *
     * @param  Zend_Acl                    $acl
     * @param  Zend_Acl_Role_Interface     $role
     * @param  Zend_Acl_Resource_Interface $resource
     * @param  string                      $privilege
     * @return boolean
     */
    public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null,
                           Zend_Acl_Resource_Interface $resource = null,
                           $privilege = null)
    {
        $identity = Zend_Auth::getInstance()->getIdentity();
        $request = Areal_Controller_Front::getInstance()->getRequest();
        $post_id = $request->getParam('id');
        if ( ! $post_id) return false;
        $postGateway = new Blog_PostGateway();
        $blogPost = Doctrine::getTable('Blog_Post')->find($post_id);
        if ($blogPost->author_id == $identity->getUserId()) return true;
        return false;
    }
}
